<table id="customer_list" class="easyui-datagrid"
       fit="true" border="false"
       singleSelect="true" fitColumns="true" pagination="true" toolbar="#toolbar_customer"
       idField="customer_id" url="y.php?r=customer/getdata">
    <thead>
    <tr>
        <th field="customer_name" width="60">客户姓名</th>
        <th field="phone" width="60">客户电话</th>
        <th field="status" width="60">状态</th>
    </tr>
    </thead>
</table>
<div id="toolbar_customer">
    <?php
    if (Yii::app()->user->checkAccess('customer_module_view')) {
        ?>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-view',plain:true" onclick="customer_view()" /a>
        <?php
    }
    if (Yii::app()->user->checkAccess('customer_module_add')) {
        ?>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="loadWin('添加客户','y.php?r=customer/showedit&customer_id=0')" /a>
        <?php
    }
    if (Yii::app()->user->checkAccess('customer_module_edit')) {
        ?>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="customer_showedit()" />
        <?php
    }
    if (Yii::app()->user->checkAccess('customer_module_remove')) {
        ?>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="customer_remove()" />
        <?php
    }
    ?>
</div>
<script>
    function customer_showedit() {
        //获取选中的列
        var selected = $("#customer_list").datagrid("getSelected");
        if(selected==null){
            alert('请选择行！');
        }else{
            //进行编辑操作
            loadWin('添加客户','y.php?r=customer/showedit&customer_id='+selected.customer_id);
        }
    }
    function customer_remove() {
        var selected = $("#customer_list").datagrid("getSelected");
        if(selected==null){
            alert('请选择行！');
        }else{
            $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
                if (r){
                    $.post('y.php?r=customer/remove',{customer_id:selected.customer_id},function (res) {
                        $("#customer_list").datagrid("reload");
                    });
                }
            });
        }
    }
    function customer_view() {
        //获取选中的列
        var selected = $("#customer_list").datagrid("getSelected");
        if(selected==null){
            alert('请选择行！');
        }else{
            //进行编辑操作
            loadWin('查看客户','y.php?r=customer/view&customer_id='+selected.customer_id);
        }
    }
</script>
